//
//  ZheXianFirstCell.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/5/2.
//  Copyright © 2017年 金橙云. All rights reserved.
//
#define WIDTH_W [UIScreen mainScreen].bounds.size.width
#import "ZheXianFirstCell.h"

@implementation ZheXianFirstCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.dataArr = [NSArray new];
        _taoLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH_W, 30)];
        _taoLab.backgroundColor = [UIColor orangeColor];
        _taoLab.textColor = [UIColor whiteColor];
        _taoLab.text = @"   主售房源销售动态(套)";
        _taoLab.font = [UIFont systemFontOfSize:14];
        [self addSubview:_taoLab];
        //分段控件
        _segmented = [[UISegmentedControl alloc] initWithItems:@[@"日",@"周",@"月",@"季",@"年"]];
        _segmented.frame = CGRectMake(10, 40, WIDTH_W-10*2, 20);
        _segmented.selectedSegmentIndex = 0;//设置默认选择项索引
        _segmented.tintColor = [UIColor orangeColor];
        [_segmented addTarget:self action:@selector(segmentedBtnClick:) forControlEvents:UIControlEventValueChanged];
        [self addSubview:_segmented];
        
        //表格
        _lineChart = [[ZFLineChart alloc] initWithFrame:CGRectMake(-40, CGRectGetMaxY(_segmented.frame),WIDTH_W+40, 205)];
        //self.lineChart.topicLabel.textColor = ZFBlack;
       _lineChart.dataSource = self;
        _lineChart.delegate = self;
        _lineChart.isResetAxisLineMinValue = YES;
        _lineChart.isShowXLineSeparate = YES;
        _lineChart.isShowYLineSeparate = YES;
       _lineChart.linePatternType = kLinePatternTypeForCurve;
        
        [self addSubview:_lineChart];
        [self.lineChart strokePath];

        _segMentIndex = 0;
    }
    return self;
}
/**
 
     _xiaoshouAnalayseArr = @[@[dayCountArr,dayNameArr],@[zhouCountArr,zhouNameArr],@[monthCountArr,monthNameArr],@[jiduCountArr,jiduNameArr],@[nianCountArr,nianNameArr]];
 */
#pragma mark - ZFGenericChartDataSource

- (NSArray *)valueArrayInGenericChart:(ZFGenericChart *)chart{
    if (_dataArr.count!=0) {
        return _dataArr[_segMentIndex][0];

    }
    return 0;
  
}

- (NSArray *)nameArrayInGenericChart:(ZFGenericChart *)chart{
    if (_dataArr.count!=0) {
        return _dataArr[_segMentIndex][1];
        
    }
    return 0;

}


- (NSArray *)colorArrayInGenericChart:(ZFGenericChart *)chart{
    //曲线的颜色
    return @[ZFLvColor];

}

- (CGFloat)axisLineMaxValueInGenericChart:(ZFGenericChart *)chart{
    
    return 100;
}


//背景格格
- (NSUInteger)axisLineSectionCountInGenericChart:(ZFGenericChart *)chart{
    return 4;
}

-(void)segmentedBtnClick:(UISegmentedControl *)sender
{
    NSLog(@"测试");
    _segMentIndex = sender.selectedSegmentIndex;
    [self.lineChart strokePath];
    
}

-(void)setSegmented:(UISegmentedControl *)segmented{
    if ([self.detegate respondsToSelector:@selector(setSegmented:)]) {
        [self.detegate didWithSegmented:segmented];
    }    
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
